package com.handydata.antifraud.rule.funcs;

import com.handydata.antifraud.to.RiskInputTO;
import com.handydata.antifraud.to.RiskMiddleTO;
import com.handydata.common.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 计算家庭住址城市、身份证城市、手机号码城市、联系人手机号码城市四个城市各自的GPS距离
 */
@Slf4j
@Component
public class Calc4CityEachDistance extends CalcDistanceByLatAndLng implements Calculate {
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public void doCalc(RiskInputTO riskInputTO, RiskMiddleTO riskMiddleTO) {

        double[] idCardCityGps = getLatAndLng(riskInputTO.getIdCardCityGps());
        double[] phoneCityGps = getLatAndLng(riskInputTO.getPhoneCityGps());
        double[] homeCityGps = getLatAndLng(riskInputTO.getHomeCityGps());
        double[] relationPhoneCityGps = getLatAndLng(riskInputTO.getRelationPhoneCityGps());
        log.info("start Calc4CityEachDistance idCardCityGps{}  phoneCityGps{} homeCityGps{} relationPhoneCityGps{}",idCardCityGps,phoneCityGps,homeCityGps,relationPhoneCityGps);

        double idCardRelationCityDis = getDistance(idCardCityGps[0], relationPhoneCityGps[0], idCardCityGps[1], relationPhoneCityGps[1]);
        double idCardHomeCityDis = getDistance(idCardCityGps[0], homeCityGps[0], idCardCityGps[1], homeCityGps[1]);
        double homeRelationCityDis = getDistance(homeCityGps[0], relationPhoneCityGps[0], homeCityGps[1], relationPhoneCityGps[1]);
        double phoneRelationCityDis = getDistance(phoneCityGps[0], relationPhoneCityGps[0], phoneCityGps[1], relationPhoneCityGps[1]);
        double idCardPhoneCityDis = getDistance(idCardCityGps[0], phoneCityGps[0], idCardCityGps[1], phoneCityGps[1]);

        riskMiddleTO.setIdCardRelationCityDis(idCardRelationCityDis);
        riskMiddleTO.setIdCardHomeCityDis(idCardHomeCityDis);
        riskMiddleTO.setHomeRelationCityDis(homeRelationCityDis);
        riskMiddleTO.setPhoneRelationCityDis(phoneRelationCityDis);
        riskMiddleTO.setIdCardPhoneCityDis(idCardPhoneCityDis);

        log.info("finish Calc4CityEachDistance idCardRelationCityDis{}  idCardHomeCityDis{} phoneRelationCityDis{} idCardPhoneCityDis{}",idCardRelationCityDis,idCardHomeCityDis,phoneRelationCityDis,idCardPhoneCityDis);

    }

}
